package Practice0915;

import Homework.Commodity;
import Homework.IUse;
import Homework.UseImp;
import com.lovo.netCRM.component.LovoComboBox;
import com.lovo.netCRM.component.LovoTable;
import com.lovo.netCRM.component.LovoTxt;

import javax.swing.*;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

public class FrameFile extends JFrame {


    private IUse use = new UseImp();
    private static List<Commodity> list = new ArrayList<>();
    static {
        Reader r = null;
        BufferedReader br = null;
        try {
            r = new FileReader("Housework09133/Product.txt");
            br = new BufferedReader(r);

            String str = null;
            while ((str = br.readLine()) != null){
                String[] array = str.split("\\s+");
                System.out.println(array[0]);
                System.out.println(array[1]);
                System.out.println(array[2]);
                System.out.println(array[3]);
                System.out.println(array[4]);
                Commodity c = new Commodity(Integer.parseInt(array[0]),array[1],array[2],array[3],array[4]);


                list.add(c);
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            try {
                br.close();
                r.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    private LovoTable table = new LovoTable(this,new String[]{"编号","商品名","单价","厂家","生产日期"},
            new String[]{"code","name","price","factory","date"},"code");

    private LovoTxt searchTxt = new LovoTxt("商品名",50,5,this);


    public FrameFile(){
        this.setLayout(null);
        this.init();

        this.setSize(600,400);
        this.setVisible(true);
        this.setDefaultCloseOperation(3);
        this.setLocationRelativeTo(null);
    }

    private void init(){
        this.table.setSizeAndLocation(50,50,400,300);
        findAll();

    }

    private void findAll(){
        table.updateLovoTable(list);
    }


    public static void main(String[] args) {
        new FrameFile();
    }
}
